<?php
  // 新增位置后端保存程序
  include_once('../conn.php');
  $position_name = $_POST['position_name'];
  $position_explain = $_POST['position_explain'];
  
  $sql = "select * from position where position_name = '$position_name'";
 
  $result = mysqli_query($conn, $sql);
  if($result) {
    alert('该位置已存在', 'position_new.php');
    exit();
  }
  
  if(strlen($position_name) < 2) {
    alert('位置名称不能小于2位', 'position_new.php');
    exit();
  }

  // 新增一条位置信息
  $sql = "insert into position (position_name, position_explain) values ('$position_name', '$position_explain')";
  $result = mysqli_query($conn, $sql);
  if($result) {
    alert('添加成功', 'position_list.php');
  } else {
    alert('添加失败', 'position_save.php');
  }

  mysqli_close($conn);
?>